local joy__jujian = fk.CreateSkill {

  name = "joy__jujian",

  tags = {  },

}



joy__jujian:addEffect(fk.EventPhaseStart, {
  name = "joy__jujian",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(joy__jujian.name) and (player.phase == Player.Finish or player.phase == Player.Start)and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos, id = player.room:askForChooseCardAndPlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, ".|.|.|.|.|^basic", "#joy__jujian-choose", joy__jujian.name, true)
    if #tos > 0 then
      event:setCostData(self, {tos[1], id})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self)[1])
    room:throwCard({event:getCostData(self)[2]}, joy__jujian.name, player, player)
    local choices = {"draw2"}
    if to:isWounded() then
      table.insert(choices, "recover")
    end
    if not to.faceup or to.chained then
      table.insert(choices, "joy__jujian_reset")
    end
    local choice = room:askForChoice(to, choices, joy__jujian.name, nil, false, {"draw2", "recover", "joy__jujian_reset"})
    if choice == "draw2" then
      to:drawCards(2, joy__jujian.name)
    elseif choice == "recover" then
      room:recover({
        who = to,
        num = 1,
        recoverBy = player,
        skillName = joy__jujian.name
      })
    else
      to:reset()
    end
  end,
})

return joy__jujian